#ifndef _DROPOUTDETECTIONWIDGET_H_
#define _DROPOUTDETECTIONWIDGET_H_

#include <QMainWindow>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QLabel>

#include "sys_data_struct.h"
#include "BRE_EEG_dataStruct.h"

#define OPEN_DROPOUTDETECTION "55 aa 01 01"
#define CLOSE_DROPOUTDETECTION "55 aa 01 03"
#define OPEN_USBTRANSMISSION "55 aa 02 01"
#define CLOSE_USBTRANSMISSION "55 aa 02 00"
#define DEVICE_INFO "55 aa 03 01"




namespace Ui {
class DropoutDetectionWidget;
}

class DropoutDetectionWidget : public QMainWindow
{
    Q_OBJECT

public:
    explicit DropoutDetectionWidget(QWidget *parent = nullptr);
    ~DropoutDetectionWidget();

    // QList<QSerialPortInfo> getSerialPortList();
    void getSerialPortList();
    void closeSerialPort();
    void readData();
    int decode(QByteArray *data);
    void setAllGreen();
    void setAllRed();
    void updateSensorLabel();
    // void writeData(const QByteArray &data);
    void sendTextData();
    void setNumOnLabel(QLabel *lbl, QString strS, long num);
    void clear_receiveTextEdit();
    // void handleSerialError(QSerialPort::SerialPortError error);

public slots:
    void on_btn_impedanceCheck_clicked(bool checked);
    void on_btn_debug_clicked(bool checked);
    void on_btn_getDeviceInfo_clicked(bool checked);
    // debug界面的按键
    void on_btn_dropout_clicked(bool checked);
    void on_btn_USBTransmission_clicked(bool checked);
    void on_btn_changeCurrent_clicked(bool checked);
    void showImpendanceFlag();


signals:
    void widgetClose(uint8_t winID);

protected:
    void closeEvent(QCloseEvent *event);

private:
    Ui::DropoutDetectionWidget *ui;
    QSerialPort *serial;
    QLabel *lblPortState;
    QLabel *lblSendNum;
    QLabel *lblRecvNum;
    ImpendanceFlag *impendanceFlag;
    QTimer *timer_readData;

    TCPEEG_PACK one_pack;
    int sendNum;
    long recvNum;
private:
    void setLabel_green(QLabel *label);
    void setLabel_red(QLabel *label);
};






#endif // !_DROPOUTDETECTION_H_

